<link rel="stylesheet" type="text/css" href="css/settings.css" />

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js"></script>
<script type="text/javascript" src="common.js"></script>
<script>
$('document').ready(function() {
    // Set the current preference value based off the id
    $('.extension-preference').each(function() {
        var id = $(this).attr('id');
        $(this).val(getPref(id));
        
    });

    // Record a change to the preference
    $('.extension-preference').change(function() {
        var id = $(this).attr('id');
        var val = $(this).val();
        setPref(id, val);
    });
    
    // Checkboxes need to be handled a little differently
    $('.extension-preference-checkbox').each(function() {
        var id = $(this).attr('id');
        $(this).attr('checked', (getPref(id)) ? 'checked' : '');
        
    });

    // Record a change to the preference
    $('.extension-preference-checkbox').change(function() {
        var id = $(this).attr('id');
        if($(this).attr('checked')) {
            var val = 1;
        } else {
            var val = 0;
        }
        setPref(id, val);
    });
    
    $('#testSabConnection').click(function() {
        $('#conResponse').html('Checking...').css('display', 'block')
        .removeClass('checkError').removeClass('checkOk');
        // Call our api queue function, and tell it to execute checkForErrors once complete
        fetchInfo(true, checkForErrors);
        return false;
    });
});

function checkForErrors() {
    // Called after a request to SABnzbd's api has been tried, 'error' should be set if there was an error
    var error = getPref('error');
    if(error) {
        $('#conResponse').html('Error: ' + error).addClass('checkError');
    } else {
        $('#conResponse').html('Connected sucessfully!').addClass('checkOk');
    }
    
    // Unsetting error here as otherwise would appear in popup - could confuse the user
    // Could move this just so it is removed when connected successfully
    setPref('error', '');
}


</script>






<div id="page">
    <div id="settings">
    
        <img id="logo" src="images/sab2_64.png" />
        <h1>SABConnect Settings</h1> 
        
        <div class="clear"></div>
        
         <div class="message">Enter your settings for SABnzbd here. Note input fields are automatically saved, just click off or press enter.</div>
        <br />
        
        <label for="sab_url">SABnzbd URL</label>
        <input class="extension-preference" type="text" id="sab_url" value="" />
        <div class="tip">The full URL you use to access SABnzbd.</div>
        <br />
        
        <label for="api_key">API KEY</label>
        <input class="extension-preference" type="text" id="api_key" value="" />
        <div class="tip">SABnzbd's API Key found in Config>General.</div>
        <br />
        <br />

        <button id="testSabConnection">Test Connection</button>
        <div id="conResponse"></div>
        <br /><br /><br />
        
        <label for="show_graph">Enable Graph</label>
        <input class="extension-preference-checkbox" type="checkbox" id="show_graph" value="1" />        
        <div class="tip">Show Google Charts Graph in popup (experimental)</div>
        <br />
        
        <div class="message info">Disabling the below will not disable the SABnzbd icon, just the functionality of sending to SABnzbd.
        If you choose to disable one, remember the icon will still show.</div>
        <br />
        
        <label for="enable_newzbin">Newzbin.com 1-Click NZB</label>
        <input class="extension-preference-checkbox" type="checkbox" id="enable_newzbin" value="1" />
        <div class="tip">1-Click NZB downloading (Account and Credit required)</div>
        <br /><br />
        
        <label for="enable_tvnzb">TVNZB.com 1-Click NZB</label>
        <input class="extension-preference-checkbox" type="checkbox" id="enable_tvnzb" value="1" />
        <div class="tip">1-Click NZB downloading</div>
        <br /><br />
        
        <label for="enable_nzbmatrix">NZBMatrix.com 1-Click NZB</label>
        <input class="extension-preference-checkbox" type="checkbox" id="enable_nzbmatrix" value="1" />   
        <div class="tip">1-Click NZB downloading (VIP Required)</div>
    
    </div>
</div>

